package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

public class StudentDao {
    private static Student[] stus = new Student[5];

    public void addStudent(Student stu) {
        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            Student s = stus[i];
            if (s == null) {
                index = i;
                break;
            }
        }
        if (index != -1) {
            stus[index] = stu;
        }
    }

    public Student[] getStus() {
        return stus;
    }

    //通过id 删除对象
    public void deleteStudentById(String id) {
        for (int i = 0; i < stus.length; i++) {
            Student s = stus[i];
            if (s != null && s.getId().equals(id)) {
                stus[i] = null;
            }
        }
    }

    //修改
    public void changeStudentById(String id, Student s) {
        for (int i = 0; i < stus.length; i++) {
            Student ss = stus[i];
            if (ss != null && ss.getId().equals(id)) {
                stus[i] = s;
            }
        }
    }
}
